<?php
require_once 'db/db.php';
require_once 'util/perm.php';

function deleteThread( $forumNum, $threadNum ) {
  if( !hasPerm('delete.thread') ) 
    return -1;

  try {
    $db = openDbConn();
    $db->beginTransaction();
    $db->exec("DELETE FROM thread WHERE thread.fid = $forumNum AND thread.id = $threadNum");
    $db->exec("DELETE FROM post WHERE post.tid = $threadNum ");
    $db->commit();
  } catch ( PDOException $e ) {
    $db->rollback();
    print "ERROR: " . $e->getMessage() . "<br />";
    die();
  }
}
// XXX remove the crux of this
// int -> int -> string -> string -> bool
function setThread( $threadNum, $mode ) {
  if( !hasPerm('edit.thread') ) 
    return -1;

  try {
    $db = openDbConn();
    $mode = $db->quote( $mode );

    $db->beginTransaction();
    $db->exec("UPDATE thread SET mode = $mode WHERE id = $threadNum");
    $db->commit();
  } catch ( PDOException $e ) {
    $db->rollback();
    print "ERROR: " . $e->getMessage() . "<br />";
    die();
  }
}
?>
